import axios from "axios";
import { useUserStore } from "@/stores/useUserStore";
const httpInstance = axios.create({
  baseURL: "http://113.46.151.113:8000/apis/",
  timeout: 5000,
});

//axios请求拦截器
httpInstance.interceptors.request.use(
  (config) => {
    //配置token
    const user = useUserStore();
    if (user.useInfo?.token) {
      //如果有token
      config.headers.Authorization = `Bearer ${user.useInfo.token}`;
    }
    return config;
  },
  (e) => Promise.reject(e),
);

httpInstance.interceptors.response.use(
  (res) => res.data,
  (e) => {
    return Promise.reject(e);
  },
);

//

export default httpInstance;
